package main

import (
	"fmt"
)

func main() {
	var str string = "ABCDEFG"

	for i, item := range str {
		fmt.Printf("str[%d]=%c \n", i, item)
	}
	fmt.Println("======================")
	for i, _ := range str {
		fmt.Printf("str[%d]=%c\n", i, str[i])
	}

	// 使用range求一个数组的和
	var array = []int{1, 2, 3, 4, 5}
	var sum int
	for i, _ := range array {
		sum += array[i]
	}
	fmt.Printf("sum of array is :%d \n", sum)

	for index, item := range array {
		if 3 == item {
			fmt.Printf("index of %d is %d \n", item, index)
		}
	}

	// map键值对使用range
	var map1 map[string]string = map[string]string{"name": "zhangxun", "nickname": "xunxun"}
	for k, v := range map1 {
		fmt.Printf("key:%10s ->value:%10s\n", k, v)
	}
}
